package cn.code.auth.authorize.web;


import cn.code.admin.model.AuthTbUrlFilter;
import cn.code.admin.dao.AuthTbUrlFilterMapper;
import cn.code.admin.constant.constant;
import cn.code.admin.dto.ExceptionMessage;
import cn.code.admin.dto.Message;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Created by wangYuDong on 2017/5/10.
 */
@Controller
@RequestMapping("/authTbUrlFilter")
public class AuthTbUrlFilterController {
    @Resource
    private AuthTbUrlFilterMapper authTbUrlFilterMapper;

    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public Page<AuthTbUrlFilter> getUserList(Page<AuthTbUrlFilter> page) {
        page.setRecords(authTbUrlFilterMapper.selectPage(page, new EntityWrapper<AuthTbUrlFilter>()));
        return page;
    }

    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Message authTbUrlFilterAdd(AuthTbUrlFilter authTbUrlFilter) {
        Integer i = authTbUrlFilterMapper.insert(authTbUrlFilter);
        if (i > 0) {
            return new Message("添加成功");
        } else {
            return new ExceptionMessage("添加失败", constant.ERROR_USER + constant.ERROR_CREATE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public Message authTbUrlFilterDelete(@PathVariable Integer id) {
        Integer i = authTbUrlFilterMapper.deleteById(id);
        if (i > 0) {
            return new Message("删除成功");
        } else {
            return new ExceptionMessage("删除失败", constant.ERROR_USER + constant.ERROR_DELETE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
    @ApiOperation(value = "修改", httpMethod = "PATCH")
    public Message authTbUrlFilterUpdate(@PathVariable Integer id, AuthTbUrlFilter authTbUrlFilter) {
        authTbUrlFilter.setId(id);
        Integer i = authTbUrlFilterMapper.updateById(authTbUrlFilter);
        if (i > 0) {
            return new Message("更新成功");
        } else {
            return new ExceptionMessage("更新失败", constant.ERROR_USER + constant.ERROR_UPDATE);
        }
    }
}
